<?php
	FLEA::loadClass('FLEA_Db_TableDataGateway');

	class	Model_Bid	extends		FLEA_Db_TableDataGateway
	{
		var		$tableName		=	'bid';
		var		$primaryKey		=	'BidID';
		
		
		function	findBid($inventionID,$firmID)
		{
			$bid 	=	$this->find('InventionID= '.$inventionID.' and FirmID='.$firmID);
			
			return $bid;
		}
		
		function	saveBid($bid)
		{
			$bidTem	=	$this->find('ID= '.$bid['ID'].' and FirmID='.$bid['FirmID'].' and Type='.$bid['Type']);
			if($bidTem['ID'] == $bid['ID'])
			{
				$bid['BidID']	=	$bidTem['BidID'];
				return $this->save($bid);
			}
			else
			{
				$bidID	=	$this->create($bid);
				return $bidID>0?1:0;
			}
		}
		
		function	findAllBudgets($id,$type)
		{
			$sql	=	"
				select bid.*,firm.Name from bid,firm
				where 
				bid.FirmID=firm.FirmID and bid.ID=".$id." and Type=".$type."
			";
			return $this->findBySql($sql);
		}
	}
?>